#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
int S,N,M;
struct Pos{
    int r,c,t;
    Pos(){};
    Pos(int rr,int cc,int tt):r(rr),c(cc),t(tt){};
};
Pos start,goal;
queue<Pos> q;
struct Dir{
    int r,c;
}dir[4]={{1,0},{-1,0},{0,1},{0,-1}};
char a[205][205];
int visited[205][205];
int main(){
    cin>>S;
    while(S--){
        cin>>N>>M;
        memset(visited,0,sizeof(visited));
        memset(a,'#',sizeof(a));
        while (!q.empty())
        {
            q.pop();
        }
        
        for(int i=1;i<=N;i++)
        for(int j=1;j<=M;j++){
            cin>>a[i][j];
            if(a[i][j]=='r'){
                start=Pos(i,j,0);
            }else if(a[i][j]=='a'){
                goal=Pos(i,j,-1);
            }
        }
        visited[start.r][start.c]=1;
        q.push(start);
        Pos p;
        while(!q.empty()){
            p=q.front();
            if(p.r==goal.r&&p.c==goal.c){
                break;
            }
            q.pop();
            
                if(a[p.r][p.c]=='x'){
                    a[p.r][p.c]='@';
                    q.push(Pos(p.r,p.c,p.t+1));
                }else{
                    int nr,nc;
                    for(int i=0;i<4;i++){
                        nr=p.r+dir[i].r;
                        nc=p.c+dir[i].c;
                        if(a[nr][nc]!='#'&&!visited[nr][nc]){
                            visited[nr][nc]=1;
                            q.push(Pos(nr,nc,p.t+1));
                        }
                    }
                }
            

            
        }
        if(q.empty()){
            cout<<"Impossible"<<endl;
        }else{
            cout<<p.t<<endl;
        }
    }
    return 0;
}